//encode cusip, gen(firm)

order firm, after(cusip)

xtset firm qrank

//connectedness is renamed
rename logeigcenwgt_normstdrankfcap logcentrality
rename logamihudsc logilliquidity

pvar logilliquidity logcentrality angvol vix dm1 , fod instlags(1/3) gmmstyle 

//IRF
//rename logstkfcap lconnect 
//rename logamihud lamihud
//rename dm1 moenyshock
//isolate gfc
quietly lpirf logcentrality logilliquidity if (qrank<35 | qrank>42) , lag(1/3) step(10) 
irf set myirfs.irf, replace
irf create Model4 
irf graph oirf, yline(0) level(95)
gr save Model4,replace

quietly lpirf logcentrality logilliquidity if (qrank>34 & qrank<43) , lag(1/3) step(10) 
irf set myirfs.irf, replace
irf create Model5 
irf graph oirf, yline(0) level(95)
gr save Model5,replace

gr combine "Model4" "Model5", col(4)





//isolate gfc for lpirf
irf set comparemodels.irf, replace
quietly lpirf logcentrality logilliquidity if (qrank<35 | qrank>42), lags(1/3) step(10) exog(dm1)
irf create lpmodel
irf graph dm, impulse(dm1) irf(lpmodel ) yline(0) level(95) saving(lpmodel, replace)

quietly lpirf logcentrality logilliquidity if (qrank>34 & qrank<43), lags(1/3) step(10) exog(dm1)
irf create lpmodel1
irf graph dm, impulse(dm1) irf(lpmodel1 ) yline(0) level(95) saving(lpmodel1, replace)

quietly lpirf logcentrality logilliquidity if (qrank<35 | qrank>42), lags(1/3) step(10) exog(vix)
irf create lpmodel2
irf graph dm, impulse(vix ) irf(lpmodel2 ) yline(0) level(95) saving(lpmodel2, replace)

quietly lpirf logcentrality logilliquidity if (qrank>34 & qrank<43), lags(1/3) step(10) exog(vix)
irf create lpmodel3
irf graph dm, impulse(vix ) irf(lpmodel3 ) yline(0) level(95) saving(lpmodel3, replace)

gr combine lpmodel.gph lpmodel1.gph lpmodel2.gph lpmodel3.gph, col(2) iscale(1)



//20241106 granger causality
pvar logilliquidity logcentrality angvol vix dm1 , fod instlags(1/3) gmmstyle 
pvargranger


